/*
CCP 1.8
Assume you have a method isSubstring which checks if one word is
 a substring of another. Given two strings, s1 and s2, write code to 
 check if s2 is a rotation of s1 using only one call to isSubstring 
 (e.g., "waterbottle" is a rotation of "erbottlewat").
*/

 #include <iostream>
#include <stdio.h>
#include <string>
#include <sstream>
#include <string.h>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <functional>
#include <cmath>
using namespace std;

struct Node
{
	char val;
	Node* next;
	Node(char v):val(v),next(NULL){}
	Node(char v,Node* n):val(v),next(n){}
};

int strcmp2(char* s1,char* s2)
{
	while(*s1 && *s1 == *s2 )
	{
		s1++;
		s2++;
	}
	return *s1 - *s2;
}
Node* FindEntryPt(Node* pHead)
{
	Node* slow = pHead;
	Node* fast = pHead;
	while(fast && fast->next)
	{
		slow = slow->next;
		fast = fast->next->next;
		if(fast == slow)break;
	}
	if(fast == NULL)return NULL;//no loop
	slow = pHead;
	while(slow != fast)
	{
		slow = slow->next;
		fast = fast->next;
	}
	return slow;
}
int main(int argc, char const *argv[])
{
	Node* C= new Node ('C');
	Node* B =new Node('B',C);
	Node* E =new Node('E',C);
	Node* D = new Node('D',E);
	C->next = D;
	Node* A= new Node('A',B);
	Node* loop_start = FindEntryPt(A);
	cout<<loop_start->val<<endl;
	return 0;
}